/*
 * @Description:
 * @Autor: Bingo
 * @Date: 2024-05-24 16:45:35
 * @LastEditors: Bingo
 * @LastEditTime: 2024-06-20 16:52:24
 */
export const getCurrentTime = () => {
  let time = new Date();
  let year = time.getFullYear();
  let month = time.getMonth() + 1;
  let day = time.getDate();
  let hour = time.getHours();
  let minute = time.getMinutes();
  let timeStr = `${year}-${month}-${day} ${hour}:${minute}`;
  return timeStr;
};
// 根据类名获取html元素
export const getElByclassName = (className: string): HTMLElement => {
  return document.getElementsByClassName(className)[0] as HTMLElement;
};

export const LS = {
  set(key: string, val: any) {
    localStorage.setItem(key, JSON.stringify(val));
  },
  get(key: string) {
    if (localStorage.getItem(key)) {
      return JSON.parse(localStorage.getItem(key) || "{}");
    }
    return undefined;
  },
};

export const UpperAndTrimData = (data: any) => {
  Object.keys(data).forEach((item) => {
    if (data[item] && typeof data[item] == "string") {
      data[item] = data[item].toUpperCase().trim();
    }
  });
  return data
};

/* 
  @parms
    val:string 输入框输入的内容
    Columns:Ref<any[]> 下拉框数据 响应式的  
    initColumns:any[] 下拉框数据 深拷贝的   
    itemCode:string 匹配属性
*/
export const handleInputEvent = (val: any,Columns:any,initColumns:any,itemCode:string) => {
  if (!val.target.value) {
    Columns.value = JSON.parse(JSON.stringify(initColumns));
  } else {
    let res: any[] = [];
    initColumns.forEach((item: any) => {
      if (item[itemCode].includes(val.target.value)) {
        res.push(item);
      }
    });
    // 输入值匹配
    Columns.value = res;
  }
};